<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<style>
</style>
<script type="text/javascript">
var processTypetreegrid;
$(function() {
	processTypetreegrid = $('#processTypetreegrid').treegrid({
        url : '${path }/processType/treeGrid',
        idField : 'id',
        treeField : 'name',
        parentField : 'pid',
        fit : true,
        fitColumns : false,
        border : false,
        frozenColumns : [ [ {
            title : 'id',
            field : 'id',
            width : 40,
            hidden : true
        } ] ],
        columns : [ [
	      {
	      width : '100',
	      title : '名称',
	      field : 'name'
	  },
       	 {
                width : '100',
                title : '部署ID',
                field : 'deploymentId'
            },
       	 {
                width : '100',
                title : '流程定义ID',
                field : 'procdefid'
            },
       	 {
                width : '100',
                title : 'key值',
                field : 'key'
       	 }, {
             width : '100',
             title : '图标',
             field : 'iconCls'
         },
           {
           width : '100',
           title : '排序',
           field : 'seq'
       }, {
           width : '100',
           title : '版本',
           field : 'version'
       },{
           field : 'pid',
           title : '上级资源ID',
           width : 150,
           hidden : true
       },
       {
           field : 'action',
           title : '操作',
           width : 320,
           formatter : function(value, row, index) {
               var str = '';
               str += $.formatString('<a href="javascript:void(0)" class="processType-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editProcessTypeFun(\'{0}\');" >编辑</a>', row.id);
               str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
               str += $.formatString('<a href="javascript:void(0)" class="processType-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="cancelProcessTypeFun(\'{0}\');" >删除</a>', row.deploymentId);
                 str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
               str += $.formatString('<a href="javascript:void(0)" class="processType-easyui-linkbutton-view" data-options="plain:true,iconCls:\'fi-magnifying-glass\'" onclick="viewProcessTypeFun(\'{0}\');" >查看</a>', row.id);
                 str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
               str += $.formatString('<a href="javascript:void(0)" class="processType-easyui-linkbutton-right" data-options="plain:true,iconCls:\'fi-universal-access\'" onclick="setProcessTypeRightFun(\'{0}\',\'{1}\');" >设置发起权限</a>', row.procdefid,row.name);
               return str;
           }
       } ] ],
       onLoadSuccess:function(data){
           $('.processType-easyui-linkbutton-edit').linkbutton({text:'编辑'});
           $('.processType-easyui-linkbutton-del').linkbutton({text:'删除'});
           $('.processType-easyui-linkbutton-view').linkbutton({text:'查看'});
           $('.processType-easyui-linkbutton-right').linkbutton({text:'设置发起权限'});
       },
       toolbar : '#processTypeToolbar'
    });
});
function addProcessTypeFun() {
    parent.$.modalDialog({
        title : '添加',
        width : 500,
        height : 300,
        href : '${path}/processType/addPage',
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_treegrid = processTypetreegrid;//因为添加成功之后，需要刷新这个treegrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#processTypeAddForm');
                f.submit();
            }
        } ]
    });
}

function setProcessTypeRightFun(procdefid,name){
	var title="设置【"+name+"】流程发起权限";
	var dialog=$('<div>').dialog({
		title:title,
		width:'80%',
		height:'80%',
		onClose : function() {
            $(this).dialog('destroy');
        },
		 href : '${path}/processType/startRight/' +procdefid,
	        buttons : [ {
	            text : '确定',
	            handler : function() {
	               //因为添加成功之后，需要刷新这个treegrid，所以先预定义好
	              var obj=$.serializeObject($('#processStartRightForm'))
	              $.ajax({
	            	  url : '${path}/processType/saveStartRight',
	            	  data:obj,
	            	  dataType:'json',
	            	  type:'post',
	            	  success:function(result){
	            		  if(result.success){
	            			  showMsg(result.msg);
	            			  dialog.dialog('close');
	            		  }
	            	  }
	              })
	               
	            }
	        } ]
	})
}
function editProcessTypeFun(id) {
    if (id == undefined) {
        var rows = processTypetreegrid.treegrid('getSelections');
        id = rows[0].id;
    } else {
        processTypetreegrid.treegrid('unselectAll').treegrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '编辑',
        width : 500,
        height : 300,
        href : '${path}/processType/editPage/' + id,
        buttons : [ {
            text : '确定',
            handler : function() {
                parent.$.modalDialog.openner_treegrid = processTypetreegrid;//因为添加成功之后，需要刷新这个treegrid，所以先预定义好
                var f = parent.$.modalDialog.handler.find('#processTypeEditForm');
                f.submit();
            }
        } ]
    });
}

function cancelProcessTypeFun(deploymentId) {
    if (deploymentId == undefined) {//点击右键菜单才会触发这个
        var rows = processTypetreegrid.treegrid('getSelections');
        deploymentId = rows[0].deploymentId;
    } else {//点击操作里面的删除图标会触发这个
        processTypetreegrid.treegrid('unselectAll').treegrid('uncheckAll');
    }
    parent.$.messager.confirm('询问', '您是否要删除吗？', function(b) {
        if (b) {
            progressLoad();
            $.post('${path}/processType/cancel/'+deploymentId, {}
            , function(result) {
                if (result.success) {
                    parent.$.messager.alert('提示', result.msg, 'info');
                    processTypetreegrid.treegrid('reload');
                }
                progressClose();
            }, 'JSON');
        }
    });
}
 function viewProcessTypeFun(id) {
    if (id == undefined) {
        var rows =  processTypetreegrid.treegrid('getSelections');
        id = rows[0].id;
    } else {
         processTypetreegrid.treegrid('unselectAll').treegrid('uncheckAll');
    }
    parent.$.modalDialog({
        title : '查看',
        width : 800,
        height : 450,
        href : '${path}/processType/viewPage/' + id,
    });
}
 function cleanprocessTypeFun(){
	 $('#searchProcesstype')[0].reset();
	 processTypetreegrid.treegrid('load', {});
 }
 
 function searchprocessTypeFun(){
	 processTypetreegrid.treegrid('load', $.serializeObject($('#searchProcesstype')));
 }
</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',border:false"  style="overflow: hidden;">
        <table id="processTypetreegrid"></table>
    </div>
    <div id="processTypeToolbar" style="display: none;">
    	<form id="searchProcesstype">
    		<table>
    			<tr>
    			<td>名称</td>
    			<td><input type="text" name="name" class="easyui-text"/>
    				  <a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-magnifying-glass',plain:true" onclick="searchprocessTypeFun();">查询</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'fi-x-circle',plain:true" onclick="cleanprocessTypeFun();">清空</a>
    			</td>
    			</tr>
    		</table>
    	</form>
	    <a onclick="addProcessTypeFun();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
	</div>
</div>

